public class IsomorphicWords {
  public int countPairs(String[] words) {
    int len = words.length;
    int count = 0;
    
    for ( int i = 0; i < len; i++ ){
      for ( int j = i+1; j < len; j++ ){
        if (words[i].length() != words[j].length())
          continue;
        String temp = words[j];
        
        //compare two words here
        for( int q = 0; q < temp.length(); q++ ){
          temp.replaceAll( temp.charAt(q), words[i].charAt(q));
        }
        
        if (temp.equals(words[i]))
          count++;

      }
    }
    return count;
  }
}